//
//  ViewController.m
//  TTTest-iOS
//
//  Created by Toj on 1/19/21.
//

#import "ViewController.h"
#import "UITextField+Extension.h"
 
@interface ViewController () <UITextFieldDelegate>
@property (strong, nonatomic) UITextField *tf_phone;
@property (strong, nonatomic) UITextField *tf_idCard;
@end
 
@implementation ViewController

- (UITextField *)tf_phone {
    if !_tf_phone {
        _tf_phone = [UITextField new];
    }
    
    return _tf_phone;
}

- (UITextField *)tf_idCard {
    if !_tf_idCard {
        _tf_idCard = [UITextField new];
    }
    
    return _tf_idCard;
}

- (void)viewDidLoad {
   [super viewDidLoad];
   
   _tf_phone.delegate = self;
   _tf_idCard.delegate = self;
}

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
   if (textField == _tf_phone) {
       return [UITextField textField:textField range:range string:string CharType:CharsType_numeral maxLength:11 separatorIndexs:@[@(3), @(8)] separator:@"-"];
   } else if (textField == _tf_idCard) {
       return [UITextField textField:textField range:range string:string CharType:CharsType_numeralAndXx maxLength:18 separatorIndexs:@[@(6), @(11), @(16)] separator:@" "];
   }
   return YES;
}



@end
